package com.runvp.rest.app;

import com.runvp.common.annotation.Log;
import com.runvp.common.core.controller.BaseController;
import com.runvp.common.core.domain.AjaxResult;
import com.runvp.common.enums.BusinessType;
import com.runvp.rest.handler.PayHandler;
import com.runvp.service.app.AppPayService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Controller
@ResponseBody
@RequestMapping("/app/pay")
public class PayController extends BaseController {

    @Autowired
    private AppPayService appPayService;
    @Autowired
    private PayHandler payHandler;


    /**
     * 查询支付状态
     */
    @Log(title = "查询支付状态", businessType = BusinessType.INSERT)
    @GetMapping("/status/query/{orderNo}")
    public AjaxResult payStatusQuery(@PathVariable String orderNo) {
        log.info("payStatusQuery:::req: {}", orderNo);
//        return AjaxResult.success("支付成功");
        //处理订单
        return AjaxResult.success("支付成功",payHandler.payCallback(orderNo));
    }

    @PostMapping("/callback")
    public void callback(HttpServletRequest request) {
        log.info("支付回调:::开始，参数，request={}",request.getParameterMap());
        appPayService.handleCallback(request);
    }



}
